package util.bio.parsers;
import java.io.*;
import java.util.*;
import util.gen.*;
import util.bio.annotation.*;

/**Shifts the bp position of UCSCGeneLines matching particular chromosomes.Good for shifting coordinates after making a composite mock chromosome from 
 * unassembled sequences/ scaffolds.*/
public class ShiftPositionsInUCSCGeneLines {

	public static void main(String[] args) {
		
		UCSCGeneModelTableReader reader = new UCSCGeneModelTableReader (new File (args[0]), 0);
		UCSCGeneLine[] lines = reader.getGeneLines();
		
		HashMap nameNumber = IO.loadFileIntoHashMap(new File (args[1]));
		
		for (int i=0; i< lines.length; i++){
			if (lines[i].getChrom().startsWith("chr")) System.out.println(lines[i]);
			else {
				int add = Integer.parseInt((String)nameNumber.get(lines[i].getChrom()));
				//System.out.println("~_"+add+lines[i]);				
				lines[i].setTss(lines[i].getTss() + add);				
				lines[i].setTxStart(lines[i].getTxStart() + add);
				lines[i].setTxEnd(lines[i].getTxEnd() + add);
				lines[i].setCdsStart(lines[i].getCdsStart() + add);
				lines[i].setCdsEnd(lines[i].getCdsEnd() + add);
				ExonIntron[] ex = lines[i].getExons();
				for (int x=0; x< ex.length; x++){
					ex[x].setStart(ex[x].getStart() +add);
					ex[x].setEnd(ex[x].getEnd() +add);
				}
				System.out.println(lines[i]);
			}
		}
	}

}
